﻿using UnityEngine;
using System.Collections;

public class scPlayerInfo : MonoBehaviour {

//	[HideInInspector]
	private const int LEVEL_OPENED = 1;
	private const int LEVEL_LOCKED = 0;


	public static bool IsLevelOpened(int level)
	{
		if (PlayerPrefs.GetInt(_GetLevelOpenedKey(level), LEVEL_LOCKED) == LEVEL_OPENED)
		{
			return true;
		}
		
		return false;
	}

	public static void SaveLevelOpened(int level)
	{
		PlayerPrefs.SetInt(_GetLevelOpenedKey(level), LEVEL_OPENED);
	}

	public static void SetHighScore(int level, int score)
	{
		PlayerPrefs.SetInt(_GetLevelHighScoreKey(level), score);
	}

	public static int GetHighScore(int level)
	{
		return PlayerPrefs.GetInt(_GetLevelHighScoreKey(level), 0);
	}

	public static void SetStars(int level, int stars)
	{
		PlayerPrefs.SetInt(_GetLevelStarsKey(level), Mathf.Clamp(stars, 0, 3));
	}

	public static int GetStars(int level)
	{
		return Mathf.Clamp(PlayerPrefs.GetInt(_GetLevelStarsKey(level), 0), 0, 3);
	}

	static string _GetLevelHighScoreKey(int level)
	{
		string levelHighScore = _GetLevelKey(level) + "_highscore";

		return levelHighScore;
	}

	static string _GetLevelStarsKey(int level)
	{
		string levelStarsKey = _GetLevelKey(level) + "_stars";

		return levelStarsKey;
	}

	static string _GetLevelOpenedKey(int level)
	{
		string levelOpenedKey = _GetLevelKey(level) + "_opened";

		return levelOpenedKey;
	}

	static string _GetLevelKey(int level)
	{
		string levelKey = "level_" + level;
		
		return levelKey;
	}

	// Use this for initialization
	void Start () {
//		PlayerPrefs.DeleteAll();
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}
